;
(function () {
	new Vue({
		el: '#report_pay',
		data: {
			quanxian: JSON.parse(localStorage.getItem('permissions')),
			pageCounts: [{
					'name': '10',
					'code': 10
				},
				{
					'name': '15',
					'code': 15
				},
				{
					'name': '20',
					'code': 20
				},
			],
			currentPage: 1,
			totalPage: 0,
			totalCount: 0,
			limit: ['10'],
			data: [],
			projectList: [],
			projectIdSelect: ['#'],
			keyword: '',
			costList: [],
			costSelect: [],
			billDate: '',
			// HTWSX合同未生效、CWWSX财务未生效、HTYSX合同已生效、HEYZZ合同终止
			contractStatus: [{
					'name': '合同未生效',
					'code': 'HTWSX'
				},
				{
					'name': '财务未生效',
					'code': 'CWWSX'
				},
				{
					'name': '合同已生效',
					'code': 'HTYSX'
				},
				{
					'name': '合同终止',
					'code': 'HEYZZ'
				},
			],
			selectedContract: [],
			payStatus: [
				// WYQWZF未逾期未支付、YQWZF逾期未支付、WYQYZF未逾期已支付、YQYZF逾期已支付
				{
					'name': '未逾期未支付',
					'code': 'WYQWZF'
				},
				{
					'name': '逾期未支付',
					'code': 'YQWZF'
				},
				{
					'name': '未逾期已支付',
					'code': 'WYQYZF'
				},
				{
					'name': '逾期已支付',
					'code': 'YQYZF'
				},
			],
			selectedPay: [],
		},
		filters: {
			paymentState(item) {
				let res;
				// WYQWZF未逾期未支付、YQWZF逾期未支付、WYQYZF未逾期已支付、YQYZF逾期已支付
				switch (item) {
					case 'WYQWZF':
						res = '未逾期未支付'
						break;
					case 'YQWZF':
						res = '逾期未支付'
						break;
					case 'WYQYZF':
						res = '未逾期已支付'
						break;
					case 'YQYZF':
						res = '逾期已支付'
						break;
					default:
						res = '--'
						break;
				}
				return res
			},
			paymentWay(item) {
				let res;
				// XJ现金、WX微信、AP支付宝、BK银行转账、ET其他
				switch (item) {
					case 'XJ':
						res = '现金'
						break;
					case 'WX':
						res = '微信'
						break;
					case 'AP':
						res = '支付宝'
						break;
					case 'BK':
						res = '银行转账'
						break;
					case 'ET':
						res = '其他'
						break;
					default:
						res = '--'
						break;
				}
				return res
			},
			contractState(item) {
				let res;
				// 合同未生效、CWWSX财务未生效、HTYSX合同已生效、HEYZZ合同终止
				switch (item) {
					case 'HTWSX':
						res = '合同未生效'
						break;
					case 'CWWSX':
						res = '财务未生效'
						break;
					case 'HTYSX':
						res = '合同已生效'
						break;
					case 'HEYZZ':
						res = '合同终止'
						break;
					default:
						res = '--'
						break;
				}
				return res
			},
			toZero: function (n) {
				return n < 10 ? '0' + n : '' + n
			},
			UTCdate: function (time) {
				if (!time) return '--';
				return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
			},
			formatNum: function (num) {
				return hlNumberUtil.formatNum(num)
			},
			formatUndefined(item) {
				if (!item) return '--'
				return item
			}
		},
		computed: {

		},
		methods: {
			//导出文件
			incomeExport() {
				hlhttp.get({
					baseUrl: exclUrl,
					url: 'resource/report_contract_income_expenditure_info/list_export',
					data: {
						project_id: this.projectIdSelect.length ? this.projectIdSelect[0] : '#',
						keyword: this.keyword || '#',
						expenditure_id: this.costSelect.length ? this.costSelect[0] : '#',
						billingDate: this.billDate || '#',
						contractStatus: this.selectedContract.length ? this.selectedContract.toString() : '#',
						paymentState: this.selectedPay.length ? this.selectedPay.toString() : '#',
					},
					success: (data) => {
						var a = document.createElement('a');
						a.href = data.excel_url;
						$('body').append($(a))
						a.click();
						setTimeout(function () {
							$(a).remove()
						}, 100);

					}
				})
			},
			contractClick() {
				this.getData()
			},
			payClick() {
				this.getData()
			},
			// 获取列表数据
			getData() {
				hlhttp.get({
					url: 'report/income_expenditure_info',
					data: {
						project_id: this.projectIdSelect.length ? this.projectIdSelect[0] : '#',
						keyword: this.keyword || '#',
						page: this.currentPage,
						page_count: this.limit + '',
						expenditure_id: this.costSelect.length ? this.costSelect[0] : '#',
						billingDate: this.billDate || '#',
						contractStatus: this.selectedContract.length ? this.selectedContract.toString() : '#',
						paymentState: this.selectedPay.length ? this.selectedPay.toString() : '#',
					},
					success: (data) => {
						this.totalPage = data.totalPage
						this.totalCount = data.totalCount
						this.data = data.datas
					}
				})
			},
			// 获取所有项目
			getProject() {
				hlhttp.get({
					url: 'user/projects',
					success: (res) => {
						res = hlArrayUtil.removeRepeat(res, 'projectId')
						res.unshift({
							projectName: '所有项目',
							projectId: '#'
						})
						this.projectList = hlArrayUtil.replaceData(res, [{
							key: 'projectName',
							rKey: 'name'
						}, {
							key: 'projectId',
							rKey: 'code'
						}]);
					}
				})
			},
			// 获取费项类型
			getCostList() {
				hlhttp.get({
					url: 'expenditures',
					data: {
						"keyword": "#",
						"type": "#",
						"flow_type": "#",
						"page": 1,
						"limit": 100000
					},
					success: res => {
						if (!res.expenditures.length) return
						let arr = []
						res.expenditures.map(item => {
							if (item.type != 'D') {
								item.name = item.name
								item.code = item.id
								arr.push(item)
							}
						})

						this.costList = arr
					},
				})
			},
			// 查询
			search() {
				this.currentPage = 1
				this.getData()
			},
			// 重置
			reset() {
				this.projectIdSelect = ['#']
				this.keyword = ''
				this.currentPage = 1
				this.limit = ['10']
				this.costSelect = []
				this.selectedContract = []
				this.selectedPay = []
				let timestamp = Date.parse(new Date());
				this.billDate = hlDateUtil.formatUTCDate(timestamp, 'yyyy-MM-dd')
				this.getData()
			},
			resetTabbar() {
				this.selectedContract = []
				this.selectedPay = []
				this.currentPage = 1
				this.getData()
			}
		},
		mounted() {
			let timestamp = Date.parse(new Date());
			this.billDate = hlDateUtil.formatUTCDate(timestamp, 'yyyy-MM-dd')

			this.getProject()
			this.getCostList()
			this.getData()
		}
	})

}())
